// Copyright 2019 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: >
    Checks error cases for the options argument to the DateTimeFormat constructor.
info: |
    InitializeDateTimeFormat ( dateTimeFormat, locales, options )
    23. Let _opt_.[[FractionalSecondDigits]] be ? GetNumberOption(_options_, `"fractionalSecondDigits"`, 0, 3, 0).

    ...
features: [Intl.DateTimeFormat-fractionalSecondDigits]
---*/


function Test() {
    const invalidOptions = [
      "LONG",
      " long",
      "short ",
      "full",
      "numeric",
      -1,
      4,
      "4",
      "-1",
      -0.00001,
      3.000001,
    ];
    for (const fractionalSecondDigits of invalidOptions) {
      assert.throws(RangeError, function() {
        new Intl.DateTimeFormat("en", { fractionalSecondDigits });
      },
      `new Intl.DateTimeFormat("en", { fractionalSecondDigits: "${fractionalSecondDigits}" }) throws RangeError`);
    }
}

// preheat
const NUMBER_OF_PREHEAT = 1;
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}

ArkTools.jitCompileAsync(Test);
assert.sameValue(ArkTools.waitJitCompileFinish(Test), true, '[JIT] JIT disabled.');

// test
const NUMBER_OF_TEST = 1; // or 2
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}
